package com.j180.servlet;

import org.springframework.beans.factory.annotation.Value;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(value="/show")
public class ShowServlet  extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        HttpSession session = req.getSession();

       // System.out.println("ShowServlet===>seesionId"+session.getId());

        //获得session对象中的值
        String islogin = (String) session.getAttribute("isLogin");

        if(islogin!=null){
            resp.getWriter().print("show all  datas");
        }else{

            resp.getWriter().print("<script>alert('please login');location.href='login.html'</script>");

        }





    }
}
